<?php
// Quick check script to count rows that would be converted by the migration
$dsn = 'mysql:host=127.0.0.1;dbname=exam;charset=utf8mb4';
$user = 'root';
$pass = 'root';
try {
    $pdo = new PDO($dsn, $user, $pass, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
} catch (Exception $e) {
    echo "DB connect failed: " . $e->getMessage() . "\n";
    exit(1);
}
$sql = 'SELECT id, options FROM ba_exam_question WHERE type IN ("single","multi","judge")';
$stmt = $pdo->query($sql);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$convertible = 0;
foreach ($rows as $r) {
    $opts = $r['options'];
    if ($opts === null || $opts === '') continue;
    $parsed = json_decode($opts, true);
    if ($parsed === null) continue;
    if (is_array($parsed) && array_values($parsed) === $parsed) {
        $convertible++;
    }
}
echo "Found {$convertible} convertible rows out of " . count($rows) . " checked.\n";
?>